<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","upp_res_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.ResName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("SNO").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","resnames.php?q="+val,true);
xmlhttp.send();
}
</script>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
</head>
<body>
<?php
include_once '../Login/databaseconnection.php';

if(!loggedin())
{
require_once '../index.php';
}
      else
   {
   date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
   if(isset($_POST['SaveChanges']))
   {
   $Resource_Type=$_POST['ResName'];
$resultr= mysql_query("SELECT * FROM resource Where Resource_Type='$type'");
if($row = mysql_fetch_array($resultr))
{
$Resource_Id=$row['Resource_Id'];
}
 if($_SESSION['Access_Type']=="Administrator")
	{
		require_once 'UPP.php';
	}   
else if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
$Serial_Number=$_POST['Serial_Number'];
   $Own_School_Id=$rowsch['School_Id'];
  	$get_LaSNo=mysql_query("SELECT * FROM resource_details WHERE Serial_Number='$Serial_Number' AND School_Id='$Own_School_Id' AND Resource_Id='$Resource_Id'");
	if($get_LaSNo)
	{
	if(mysql_num_rows($get_LaSNo)!=0)
{	 
	require_once 'UPP.php';
	}
	else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
	}
	}
	}
	
	else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
}
	$Resource_Id="";
	$Serial_Number="";
   if(isset($_POST['Edit_This']))
	   {
$ResName=$_POST['ResName'];
$resultr= mysql_query("SELECT * FROM resource Where Resource_Type='$ResName'");
if($row = mysql_fetch_array($resultr))
{
$Resource_Id=$row['Resource_Id'];
}
		$Serial_Number=$_POST['Serial_Number'];
		
 if($ResName==""||$Serial_Number=="Select One")
	   {
	$_SESSION['errornorow']="Not enough inputs,Please select the Resource type and Serial number!";
}
	  if($ResName!=""&&$Serial_Number!="Select One")
	   {
	   $_SESSION['Resource_Id']=$Resource_Id;
	    $_SESSION['Lab_Id']=$Serial_Number;
	   if($_SESSION['Access_Type']=="Administrator")
	{
		$result=mysql_query("SELECT * FROM resource_details WHERE Resource_Id='$Resource_Id' AND Serial_Number='$Serial_Number'");
		if(mysql_num_rows($result)==0)
		{
			$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
		}
	}
   else if($_SESSION['Access_Type']=="Teacher in Charge")
	{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
	{
   $Own_School_Id=$rowsch['School_Id'];
  	$get_LaSNo=mysql_query("SELECT * FROM resource_details WHERE Serial_Number='$Serial_Number' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($get_LaSNo)>0)
		{	
	if($row_LaSNo=mysql_fetch_array($get_LaSNo))
	{
	 $De_Lab_Id=$row_LaSNo['Lab_Id'];
	 $get_res=mysql_query("SELECT * FROM lab WHERE School_Id='$Own_School_Id' AND Lab_Id='$De_Lab_Id'");
	 if(mysql_num_rows($get_res)!=0)
		{
	$result=mysql_query("SELECT * FROM resource_details WHERE Resource_Id='$Resource_Id' AND Serial_Number='$Serial_Number'");
	   if(mysql_num_rows($result)==0)
		{
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
		}
		}
		if(mysql_num_rows($get_res)==0)
		{
			$_SESSION['errornorow']="Sorry you are not allowed to do this!";
		}
	}
	}
	if(mysql_num_rows($get_LaSNo)==0)
		{
			$_SESSION['errornorow']="Sorry you are not allowed to do this!";
		}
  }
   else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
 }
 else
	   {
	   $_SESSION['errornorow']="Sorry you are not allowed to do this!";
	   }
   }
  
   }
   ?><?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?> 
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttable">
<br/>
<form action="#" method="POST" name="form1">
  <table width="592" border="0" class="tablefontv">
    <tr>
      <td colspan="5"  scope="row" class="err"><?php
		if(isset($_POST['Edit_This'])||isset($_POST['SaveChanges']))
{
if(isset($_SESSION['error']))
	{ 
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'].'<br/>';
		unset($_SESSION['error']);
	}
if(isset($_SESSION['errorempt']))
	{ 
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorempt'].'<br/>';
		unset($_SESSION['errorempt']);
	}
		if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
		if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
}
		?>
		</td>
      </tr>
    <tr>
      <td width="42" rowspan="3"  scope="row" bgcolor="#6AB5FF">&nbsp;</td>
      <td width="137"  scope="row" bgcolor="#6AB5FF">Resource's Type:</td>
      <td width="168" bgcolor="#999999">
       <?php
	  if(isset($_POST['SaveChanges']))
	{
	$Resource_Id=$_SESSION['Res_Id'];
	$res=mysql_query("SELECT * FROM resource WHERE Resource_Id='$Resource_Id'");
	   if($row=mysql_fetch_array($res))
  {
	 $Res_Name=$row['Resource_Type'];
	 }
	 }
	 echo "<input type='text' id='ResName' name='ResName' onKeyUp='showHint(this.value)' value='$Res_Name' onClick='cleartbox()' size='25'/>";
	  ?></td>
      <td width="83" rowspan="2" bgcolor="#6AB5FF">&nbsp;</td>
      <td width="140" rowspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td scope="row" bgcolor="#6AB5FF">Serial Number:</td>
      <td bgcolor="#999999"><div id="SNO"><select name="Serial_Number" id="select">
        <?php
		 if(isset($_POST['SaveChanges']))
	  {
	  $Se_Number=$_SESSION['Se_Number'];
	    echo '<option value="'.$Se_Number.'">'.$Se_Number.'</option>';
		 unset($_SESSION['Se_Number']);
	  }
	  if(isset($_POST['Edit_This']))
	  {
	echo '<option value="'.$Serial_Number.'">'.$Serial_Number.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	   
	   if($Resource_Id!="")
	  {
	  $res=mysql_query("SELECT DISTINCT(Serial_Number) FROM resource_details WHERE Resource_Id='$Resource_Id'");
	  }
	  if($Resource_Id=="")
	  {
	  $res=mysql_query("SELECT DISTINCT(Serial_Number) FROM resource_details");
	  }
  while($row=mysql_fetch_array($res))
  {
	  $Ser_Number=$row['Serial_Number'];
	  if($Serial_Number!=$Ser_Number)
	  {
	  echo '<option value="'.$Ser_Number.'">'.$Ser_Number.'</option>';
	  }
  }
	  ?>
      </select></div></td>
      </tr>
    <tr>
      <th colspan="3" scope="row" bgcolor="#6AB5FF"><a href="UpdateRes.php" class="reset">Reset |</a>
        <input name="Edit_This" align="middle" type="submit" value="Edit this" class="buttonok"/></th>
      <th scope="row">&nbsp;</th>
      </tr>
    
  </table>
  <br/>
  <br/>
  
</form>
<form action="#" method="POST">
    <?php 
if(isset($_POST['Edit_This']))
	   {
	$ResName=$_POST['ResName'];
$resultr= mysql_query("SELECT * FROM resource Where Resource_Type='$ResName'");
if($row = mysql_fetch_array($resultr))
{
$Resource_Id=$row['Resource_Id'];
}
    $Serial_Number=$_POST['Serial_Number'];
	
	$_SESSION['Resource_Id']=$Resource_Id;
	    $_SESSION['Serial_Number']=$Serial_Number;
	 if($ResName!=""&&$Serial_Number!="Select One")
	   {
	   if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
$Serial_Number=$_POST['Serial_Number'];
   $Own_School_Id=$rowsch['School_Id'];
   	$get_LaSNo=mysql_query("SELECT * FROM resource_details WHERE Serial_Number='$Serial_Number' AND School_Id='$Own_School_Id'");
	if(mysql_num_rows($get_LaSNo)>0)
		{
	if($row_LaSNo=mysql_fetch_array($get_LaSNo))
{
	 $De_Lab_Id=$row_LaSNo['Lab_Id'];
	 $get_res=mysql_query("SELECT * FROM lab WHERE School_Id='$Own_School_Id' AND Lab_Id='$De_Lab_Id'");
	 if(mysql_num_rows($get_res)!=0)
	{
	$result=mysql_query("SELECT * FROM resource_details WHERE Resource_Id='$Resource_Id' AND Serial_Number='$Serial_Number'");
	if(mysql_num_rows($result)!=0)
  {
  echo '<table width="354" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
 
    $Resource_Id=$row['Resource_Id'];
	$Lab_Id=$row['Lab_Id'];
   $Serial_Number=$row['Serial_Number'];
	$Functioning=$row['Functioning'];
    $Brand_Name=$row['Brand_Name'];
    $Date_Of_Supplied=$row['Date_Of_Supplied'];
    $Name_Of_Supplier=$row['Name_Of_Supplier'];
    $Funding_Source=$row['Funding_Source'];
	$School_Id=$row['School_Id'];
 
      echo '<tr>';
        echo '<th width="200" height="29" scope="row">';
		echo "Resource Id:";
		echo '</th>';
        echo '<td width="144">';
	echo "<input type='text' name='Resource_Id' value='$Resource_Id'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Lab Id:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Lab_Id' value='$Lab_Id'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Serial Number:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Serial_Number' value='$Serial_Number'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Functioning:";
		echo '</th>';
       echo '<td>';
	 
	  
	   if($row['Functioning']=="Yes")
		   {
           echo '<input type="radio" name="Functioning" value="Yes" checked="checked"/>';
		    echo "Yes";
			echo '<input type="radio" name="Functioning" value="No"/>';
		    echo "No";
		   }
               
           echo "<br />";
		   if($row['Functioning']=="No")
		   {
			   echo '<input type="radio" name="Functioning" value="Yes"/>';
		    echo "Yes";
           echo '<input type="radio" name="Functioning" value="No" checked="checked"/>';
		    echo "No";
		   }
		 
		    echo '</td>';
			 echo '</tr>';
           echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Brand Name:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Brand_Name' value='$Brand_Name'>";
            
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Date Of Supplied:"; 
		echo '</th>';
        echo '<td>';
		if(isset($Date_Of_Supplied))
		{
		echo "<input type='text' name='Date_Of_Supplied' value='$Date_Of_Supplied' class='inputDate' id='inputDate'>";
		}
		else
		{
		echo "<input type='text' name='Date_Of_Supplied' value='$t_d' class='inputDate' id='inputDate'>";
		}
		echo '</td>';
      echo '</tr>';
	  
	  echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Name Of Supplier:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Name_Of_Supplier' value='$Name_Of_Supplier'>";
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Funding Source:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Funding_Source' value='$Funding_Source'>";
		echo '</td>';
      echo '</tr>';
	  
	  echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "School Id:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='School_Id' value='$School_Id'>";
		echo '</td>';
      echo '</tr>';
	 }
   echo '</table>';
   
   echo "<br/>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" class="buttonok"/>';
 }
 }
  }
	}
	}
	}
	   if($_SESSION['Access_Type']=="Administrator")
{
     $result=mysql_query("SELECT * FROM resource_details WHERE Resource_Id='$Resource_Id' AND Serial_Number='$Serial_Number'");
  
  if(mysql_num_rows($result)!=0)
  {
  echo '<table width="354" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
 
    $Resource_Id=$row['Resource_Id'];
	$Lab_Id=$row['Lab_Id'];
   $Serial_Number=$row['Serial_Number'];
	$Functioning=$row['Functioning'];
    $Brand_Name=$row['Brand_Name'];
    $Date_Of_Supplied=$row['Date_Of_Supplied'];
    $Name_Of_Supplier=$row['Name_Of_Supplier'];
    $Funding_Source=$row['Funding_Source'];
	$School_Id=$row['School_Id'];
 
      echo '<tr>';
        echo '<th width="200" height="29" scope="row">';
		echo "Resource Id:";
		echo '</th>';
        echo '<td width="144">';
	echo "<input type='text' name='Resource_Id' value='$Resource_Id'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Lab Id:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Lab_Id' value='$Lab_Id'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Serial Number:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Serial_Number' value='$Serial_Number'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Functioning:";
		echo '</th>';
       echo '<td>';
	 
	  
	   if($row['Functioning']=="Yes")
		   {
           echo '<input type="radio" name="Functioning" value="Yes" checked="checked"/>';
		    echo "Yes";
			echo '<input type="radio" name="Functioning" value="No"/>';
		    echo "No";
		   }
               
           echo "<br />";
		   if($row['Functioning']=="No")
		   {
			   echo '<input type="radio" name="Functioning" value="Yes"/>';
		    echo "Yes";
           echo '<input type="radio" name="Functioning" value="No" checked="checked"/>';
		    echo "No";
		   }
		 
		    echo '</td>';
			 echo '</tr>';
           echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Brand Name:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Brand_Name' value='$Brand_Name'>";
            
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Date Of Supplied:"; 
		echo '</th>';
        echo '<td>';
		if(isset($Date_Of_Supplied))
		{
		echo "<input type='text' name='Date_Of_Supplied' value='$Date_Of_Supplied' class='inputDate' id='inputDate'>";
		}
		else
		{
		echo "<input type='text' name='Date_Of_Supplied' value='$t_d' class='inputDate' id='inputDate'>";
		}
		echo '</td>';
      echo '</tr>';
	  
	  echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Name Of Supplier:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Name_Of_Supplier' value='$Name_Of_Supplier'>";
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "Funding Source:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Funding_Source' value='$Funding_Source'>";
		echo '</td>';
      echo '</tr>';
	  echo '<tr>';
        echo '<th height="29" scope="row">';
		echo "School Id:"; 
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='School_Id' value='$School_Id'>";
		echo '</td>';
      echo '</tr>';
	 }
   echo '</table>';
   
   echo "<br/>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" class="buttonok"/>';
 }
  }
 }	
	}  
	   ?>
       </form>
  </div>
  <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div></div> 
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">RESOURCES</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php

}
?>
</body>
</html>